home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS11.ADF
/
Modula-2
/
CaseConvert
/
case.mod
< prev
next >
Wrap
Text File
|
1986-08-05
|
5KB
|
125 lines
MODULE CaseConversion;
(* This program reads a Modula-2 program and converts all
key words to upper case, and other identifiers to the
form in which they were found first.
Modified: 4/3/86 by Richie Bielak
On the AMiga make sure files are closed.
5/18/86 Make sure the heap is destroyed, so that
Amiga gets it's memory back.
Copyright (c) 1986 - by Richie Bielak
This program maybe freely copied, but please leave my name in.
Thanks....Richie
*)
FROM Storage IMPORT DestroyHeap;
FROM InOut IMPORT OpenInput, OpenOutput, CloseInput,
CloseOutput, Done, WriteString;
FROM Symbols IMPORT InsertSymbol, FindSymbol;
FROM Scanner IMPORT TokenType, GetToken;
IMPORT Terminal;
(* Insert standard identifiers into the symbol table *)
PROCEDURE InitTable;
BEGIN
InsertSymbol('AND'); InsertSymbol('ARRAY'); InsertSymbol('BEGIN');
InsertSymbol('BY'); InsertSymbol('CASE'); InsertSymbol('CONST');
InsertSymbol('DEFINITION'); InsertSymbol('DIV'); InsertSymbol('DO');
InsertSymbol('ELSE'); InsertSymbol('ELSIF'); InsertSymbol('END');
InsertSymbol('EXIT'); InsertSymbol('EXPORT'); InsertSymbol('FOR');
InsertSymbol('FROM'); InsertSymbol('IF'); InsertSymbol('IMPLEMENTATION');
InsertSymbol('IMPORT'); InsertSymbol('IN'); InsertSymbol('LOOP');
InsertSymbol('MOD'); InsertSymbol('MODULE'); InsertSymbol('NOT');
InsertSymbol('OF'); InsertSymbol('OR'); InsertSymbol('POINTER');
InsertSymbol('PROCEDURE'); InsertSymbol('QUALIFIED'); InsertSymbol('RECORD');
InsertSymbol('REPEAT'); InsertSymbol('RETURN'); InsertSymbol('SET');
InsertSymbol('THEN'); InsertSymbol('TO'); InsertSymbol('TYPE');
InsertSymbol('UNTIL'); InsertSymbol('VAR'); InsertSymbol('WHILE');
InsertSymbol('WITH'); InsertSymbol('ABS'); InsertSymbol('BITSET');
InsertSymbol('BOOLEAN'); InsertSymbol('CAP'); InsertSymbol('CARDINAL');
InsertSymbol('CHAR'); InsertSymbol('CHR'); InsertSymbol('DEC');
InsertSymbol('DISPOSE'); InsertSymbol('EXCL'); InsertSymbol('FALSE');
InsertSymbol('FLOAT'); InsertSymbol('HALT'); InsertSymbol('HIGH');
InsertSymbol('INC'); InsertSymbol('INCL'); InsertSymbol('INTEGER');
InsertSymbol('NEW'); InsertSymbol('NIL'); InsertSymbol('ODD');
InsertSymbol('ORD'); InsertSymbol('PROC'); InsertSymbol('REAL');
InsertSymbol('TRUE'); InsertSymbol('TRUNC'); InsertSymbol('VAL');
InsertSymbol('InOut'); InsertSymbol('Write'); InsertSymbol('WriteString');
InsertSymbol('WriteLn'); InsertSymbol('Read'); InsertSymbol('ReadString');
InsertSymbol('ReadLn'); InsertSymbol('OpenInput');
InsertSymbol('OpenOutput'); InsertSymbol('Done'); InsertSymbol('termCH');
InsertSymbol('LONGCARD'); InsertSymbol('LONGINT');
END InitTable;
PROCEDURE ProcessFile;
VAR
CurrentToken : TokenType;
PrettyToken, Token : ARRAY [0..80] OF CHAR;
CommentLevel : CARDINAL;
InSingleQuote,
InDoubleQuote : BOOLEAN;
BEGIN
(* Initialize local variables *)
CommentLevel := 0; InSingleQuote := FALSE; InDoubleQuote := FALSE;
(* Do this until end of file *)
WHILE GetToken (CurrentToken, Token) DO
CASE CurrentToken OF
Identifier:
IF NOT (InSingleQuote OR InDoubleQuote) AND
(CommentLevel = 0) THEN
IF FindSymbol (Token, PrettyToken) THEN
WriteString (PrettyToken)
ELSE
InsertSymbol (Token); WriteString (Token)
END
ELSE
WriteString (Token);
END;
|
OpenComment: IF NOT (InSingleQuote AND InDoubleQuote) THEN
INC (CommentLevel);
END;
|
CloseComment: IF NOT (InSingleQuote AND InDoubleQuote) AND
(CommentLevel > 0) THEN
DEC (CommentLevel)
END;
|
SingleQ: IF NOT InDoubleQuote AND (CommentLevel = 0) THEN
InSingleQuote := NOT InSingleQuote;
END;
|
DoubleQ: IF NOT InSingleQuote AND (CommentLevel = 0) THEN
InDoubleQuote := NOT InDoubleQuote
END;
END; (* CASE *)
END; (* WHILE *)
END ProcessFile;
BEGIN
InitTable;
Terminal.WriteString ('=== Modula-2 Case Converter ===');
Terminal.WriteLn;
OpenInput ('.MOD');
IF NOT Done THEN
Terminal.WriteString('Cannot open input file !!');
Terminal.WriteLn;
ELSE
OpenOutput ('.MOD');
IF Done THEN
ProcessFile;
CloseOutput ();
ELSE
Terminal.WriteString ("Cannot open output file !!!");
Terminal.WriteLn;
END;
CloseInput();
END;
DestroyHeap;
END CaseConversion.